**************************************************************************************
** title:		replication for 'Is there a `Youthquake'? 							**
** authors:		ruth dassonneville & ian mcallister 								**
** date:		February 2025 														**
** machine:		MacOS Sonoma 14.4													**
** software:	Stata 18 															**
**************************************************************************************


* --------------
* preamble
* --------------

	** set style for graphs
	grstyle init
	grstyle set plain, nogrid noextend	

	** install additional packages (uncomment if not installed yet)
	*net install grc1leg,from( http://www.stata.com/users/vwiggins/)
	
	** ensure large datasets can be loaded
	clear
	clear matrix
	clear mata
	set maxvar 15000

* -----------------------------------------------------
* study 1, variable coding and merge with macro-data
* -----------------------------------------------------

	** load data study 1 (WPID, available at https://wpid.world/resources/)
	cd "~/Dropbox/youthquake-replication/data"
	use "gmp.dta" , clear
	
	** decade dummies (disregarding data pre 1950 and post 2020)
	gen decade=1940 if year>=1940 & year<=1949
	replace decade=1950 if year>=1950 & year<=1959
	replace decade=1960 if year>=1960 & year<=1969
	replace decade=1970 if year>=1970 & year<=1979
	replace decade=1980 if year>=1980 & year<=1989
	replace decade=1990 if year>=1990 & year<=1999
	replace decade=2000 if year>=2000 & year<=2010
	replace decade=2010 if year>=2010 & year<=2020

	** new age variable
	gen agegroup=1 if age<=29
	replace agegroup=2 if age>=30 & age<=39
	replace agegroup=3 if age>=40 & age<=49
	replace agegroup=4 if age>=50 & age<=59
	replace agegroup=5 if age>=60

	label define agegroupl 1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+"
	label values agegroup agegroupl

	** approximate year of birth
	gen yearbirth=year-age

	** generations
	gen generation=1 if yearbirth<1928 & yearbirth!=.			// greatest -1928
	replace generation=2 if yearbirth>=1928 & yearbirth<=1945 	// silent generation 1928-45
	replace generation=3 if yearbirth>=1946 & yearbirth<=1964 	// boomers 1946-64
	replace generation=4 if yearbirth>=1965 & yearbirth<=1980 	// gen X 1965-80
	replace generation=5 if yearbirth>=1981 & yearbirth<=1996 	// millenials 1981-96
	replace generation=6 if yearbirth>=1997 & yearbirth!=. 		// gen Z 1997- 

	label define generationl 1 "Greatest" 2 "Silent" 3 "Boomers" 4 "Gen. X" 5 "Millenials" 6 "Gen. Z"
	label values generation generationl

	** religion	
	gen religionlim=1 if religion=="None"
	replace religionlim=2 if religion=="Catholic"
	replace religionlim=3 if religion=="Christian"
	replace religionlim=3 if religion=="Lutheran/Orthodox"
	replace religionlim=3 if religion=="Orthodox"
	replace religionlim=3 if religion=="Other Christian"
	replace religionlim=3 if religion=="Protestant"
	replace religionlim=4 if religion=="Buddhist"
	replace religionlim=4 if religion=="Buddhist / Taoist"
	replace religionlim=4 if religion=="Buddhist / Taoist / Other"
	replace religionlim=4 if religion=="Hindu"
	replace religionlim=4 if religion=="Hindu / Sikh"
	replace religionlim=4 if religion=="Mouridiya"
	replace religionlim=4 if religion=="Muslim"
	replace religionlim=4 if religion=="Other Muslim"
	replace religionlim=4 if religion=="Shia"
	replace religionlim=4 if religion=="Sikh"
	replace religionlim=4 if religion=="Sunni"
	replace religionlim=4 if religion=="Tijaniya"

	label define religionliml 1 "no religion" 2 "catholic" 3 "other christian" 4 "other"
	label values religionlim religionliml

	** ethnicity 	
	gen white=0 if race!="."
	replace white=1 if race=="European"
	replace white=1 if race=="White"

	gen minority=1 if white==0
	replace minority=0 if white==1
	replace minority=. if race==""	

	** new left variable that does not consider social liberal parties as left
	gen voteleft_new=voteleft
	replace voteleft_new=0 if votelib==1

	** keep countries in West + Greece (which we also consider Western)
	keep if west==1 | isoname=="Greece"		
	keep if decade!=.

	** merge with data on positions and polarization (by year) based on CMP
	gen isoyear=iso+string(year)

	merge m:1 isoyear using "cmp_positions.dta" 
	drop if _merge==2
	drop _merge

	** merge with gallagher's election indices data 
	merge m:1 isoyear using "gallagher-indices-formerge.dta" 
	drop if _merge==2
	drop _merge
	
	** numerical country code for analyses
	encode iso, gen(isonum)


* ----------------------------------
* study 1 descriptive plot (fig 1)
* ----------------------------------

	** set working directory for saving graphs and tables
	cd "~/Dropbox/youthquake-replication/tables and figures"

	** show age gaps by country in 2010s
	set more off
	tempname agegap_countries
	
	postfile `agegap_countries' sample b_old se_old using agegap_countries.dta, replace
	
	foreach lname of numlist 1(1)22 {  		// loop to repeat the same command for each country
	local t : label iso `lname'
		noisily reg voteleft_new i.agegroup if decade==2010 & isonum==`lname' 
		post `agegap_countries' (`lname') (`=_b[5.agegroup]') (`=_se[5.agegroup]')
		}
		
	postclose `agegap_countries'
	
	preserve
	use "agegap_countries.dta", clear
	
	sort b_old
	gen order=_n

	label define samplelabel 1 "AT" 2 "AU" 3 "BE" 4 "CA" 5 "CH" 6 "DE" 7 "DK" 8 "ES" 9 "FI" 10 "FR" 11 "GB" 12 "GR" 13 "IE" 14 "IS" 15 "IT" 16 "LU" 17 "NL" 18 "NO" 19 "NZ" 20 "PT" 21 "SE" 22 "US"
	label values sample samplelabel
	
	label define orderlabel  1 "AU" 2 "GB" 3 "LU" 4 "NZ" 5 "CH" 6 "CA" 7 "US" 8 "FR" 9 "GR" 10 "FI" 11 "ES" 12 "AT" 13 "IE" 14 "IT" 15 "BE" 16 "NO" 17 "PT" 18 "DE" 19 "SE" 20 "NL" 21 "DK" 22 "IS"

	label values order orderlabel
	
	gen b_young=-1*b_old
	
	gen lower=b_young-(1.96*se_old)
	gen upper=b_young+(1.96*se_old)

	tw rspike lower upper order  || scatter b_young order  , msymbol(circle) xla(1/22 , valuelabel  ) xtitle("") sort(b_young) legend(off) yline(0, lpattern(dash)) ytitle("Effect of being 18-29 vs. 60+") xsize(4.5) saving(figure1.gph, replace)
	restore
	
	
* -------------------------------------
* study 1 main analyses, Figure 2
* -------------------------------------

	** estimation: agegroup X positions left and non-left parties
	eststo m1: mixed voteleft_new i.agegroup##c.maxleft i.agegroup##c.minnonleft   i.sex  effnv lsq || isoyear:agegroup  if year>=2000, var

	** marginal effects plot, Figure 2a	
	margins, at(maxleft=(3.5(0.1)5.6) agegroup=(1 5))
	marginsplot, title("") recast(line) recastci(rarea) addplot(hist maxleft if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) xtitle("Position most conservative left party") ytitle("Probability of voting for left") saving(maxleft_interaction.gph, replace)

	** marginal effects plot, Figure 2b	
	margins, at(minnonleft=(3.4(0.1)5.7) agegroup=(1 5))
	marginsplot, title("") recast(line) recastci(rarea) addplot(hist minnonleft if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) xtitle("Position most progressive non-left party") ytitle("Probability of voting for left") saving(minnonleft_interaction.gph, replace)

	** table with detailed estimates for Appendix C
	esttab m1  using appendixC_table1.rtf, b(3) se(3) nogap r2 replace
	
	
* ---------------------------------------
* study 1, information for the appendix
* ---------------------------------------	

	** detailed estimates by country, appendix A
	eststo m1: reg voteleft_new i.agegroup if decade==2010 & iso=="AU"
	eststo m2: reg voteleft_new i.agegroup if decade==2010 & iso=="GB"
	eststo m3: reg voteleft_new i.agegroup if decade==2010 & iso=="LU"
	eststo m4: reg voteleft_new i.agegroup if decade==2010 & iso=="NZ"
	eststo m5: reg voteleft_new i.agegroup if decade==2010 & iso=="CH"
	eststo m6: reg voteleft_new i.agegroup if decade==2010 & iso=="CA"
	eststo m7: reg voteleft_new i.agegroup if decade==2010 & iso=="US"
	eststo m8: reg voteleft_new i.agegroup if decade==2010 & iso=="FR"
	eststo m9: reg voteleft_new i.agegroup if decade==2010 & iso=="GR"
	eststo m10: reg voteleft_new i.agegroup if decade==2010 & iso=="FI"
	eststo m11: reg voteleft_new i.agegroup if decade==2010 & iso=="ES"
	eststo m12: reg voteleft_new i.agegroup if decade==2010 & iso=="AT"
	eststo m13: reg voteleft_new i.agegroup if decade==2010 & iso=="IE"
	eststo m14: reg voteleft_new i.agegroup if decade==2010 & iso=="IT"
	eststo m15: reg voteleft_new i.agegroup if decade==2010 & iso=="BE"
	eststo m16: reg voteleft_new i.agegroup if decade==2010 & iso=="NO"
	eststo m17: reg voteleft_new i.agegroup if decade==2010 & iso=="PT"
	eststo m18: reg voteleft_new i.agegroup if decade==2010 & iso=="DE"
	eststo m19: reg voteleft_new i.agegroup if decade==2010 & iso=="SE"
	eststo m20: reg voteleft_new i.agegroup if decade==2010 & iso=="NL"
	eststo m21: reg voteleft_new i.agegroup if decade==2010 & iso=="DK"
	eststo m22: reg voteleft_new i.agegroup if decade==2010 & iso=="IS"
	
	esttab m1 m2 m3 m4 m5 m6 using appendixA_table1.rtf, b(3) se(3) nogap replace
	esttab m7 m8 m9 m10 m11 m12 using appendixA_table2.rtf, b(3) se(3) nogap replace
	esttab m13 m14 m15 m16 m17 m18 using appendixA_table3.rtf, b(3) se(3) nogap replace
	esttab m19 m20 m21 m22 using appendixA_table4.rtf, b(3) se(3) nogap replace

	** additional socio-demographic controls, Appendix D
	eststo m1: mixed voteleft_new i.agegroup##c.maxleft i.agegroup##c.minnonleft   i.sex  effnv lsq || isoyear:	agegroup  if year>=2000, var
	eststo m2: mixed voteleft_new i.agegroup##c.maxleft i.agegroup##c.minnonleft   i.sex i.educ effnv lsq || isoyear:agegroup  if year>=2000, var
	eststo m3: mixed voteleft_new i.agegroup##c.maxleft i.agegroup##c.minnonleft   i.sex i.educ i.religionlim effnv lsq || isoyear:agegroup  if year>=2000, var
	eststo m4: mixed voteleft_new i.agegroup##c.maxleft i.agegroup##c.minnonleft   i.sex i.educ i.minority effnv lsq || isoyear:agegroup  if year>=2000, var

	esttab m1 m2 m3 m4  using appendixD_table1.rtf, b(3) se(3) nogap r2 replace

	** extending time period to 1980-2020, Appendix E
	eststo m1: mixed voteleft_new i.agegroup##c.maxleft i.agegroup##c.minnonleft  i.sex  effnv lsq || isoyear:		agegroup  if year>=1980, var

	esttab m1  using appendixE_table1.rtf, b(3) se(3) nogap r2 replace
	
	** alternative indicators for positions of parties, Appendix G

		* estimation with vote-share weighted indicator
	mixed voteleft_new i.agegroup##c.leftSocietyLR_w i.agegroup##c.nonleftSocietyLR_w i.sex effnv lsq || isoyear:agegroup  if year>=2000, var

		* marginal effects, Figure G1a
	margins, at(leftSocietyLR_w=(3.6(0.2)5.6) agegroup=(1 5))
	marginsplot, title("") recast(line) recastci(rarea)  addplot(hist leftSocietyLR_w if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) xtitle("Sociocultural position left parties") ytitle("Probability of voting for left") saving(figureG1a.gph, replace)

		* marginal effects, Figure G1b
	margins, at(nonleftSocietyLR_w=(4.1(0.2)6.5) agegroup=(1 5))
	marginsplot, title("") recast(line) recastci(rarea)  addplot(hist nonleftSocietyLR_w if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) xtitle("Sociocultural position non-left parties") ytitle("Probability of voting for left") saving(figureG1b.gph, replace)

		* create additional variables
	gen differenceLeftNonleft= nonleftSocietyLR_w - leftSocietyLR_w 
	gen differenceMaxMin=minnonleft-maxleft

		* estimation with difference between vote-share weighted sociocultural position of non-left parties & vote-share weighted sociocultural position of left parties
	mixed voteleft_new i.agegroup##c.differenceLeftNonleft    i.sex  effnv lsq || isoyear:agegroup  if year>=2000, var
	sum differenceLeftNonleft if e(sample)==1

		* marginal effects, Figure G2
	margins, at(differenceLeftNonleft=(-0.5(0.1)1.8) agegroup=(1 5))
	marginsplot, title("") recast(line) recastci(rarea) addplot(hist differenceLeftNonleft if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) xtitle("Cultural position right parties - cultural position left parties (weighted)") ytitle("Probability of voting for left") saving(figureG2.gph, replace)

		* estimation with difference between sociocultural position of most progressive non-left party &  sociocultural position of most conservative left party
	mixed voteleft_new i.agegroup##c.differenceMaxMin    i.sex  effnv lsq || isoyear:agegroup  if year>=2000, var
	sum differenceMaxMin if e(sample)==1

		* marginal effects, Figure G3
	margins, at(differenceMaxMin=(-1.1(0.1)1.2) agegroup=(1 5))
	marginsplot, title("") recast(line) recastci(rarea) addplot(hist differenceMaxMin if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) xtitle("Cultural position right parties - cultural position left parties") ytitle("Probability of voting for left") saving(figureG3.gph, replace)


	** interaction with ENEP, Appendix H

		* estimation
	eststo m1: mixed voteleft_new i.agegroup##c.maxleft i.agegroup##c.minnonleft   i.agegroup##c.effnv i.sex lsq || isoyear:agegroup  if year>=2000, var

		* table for inclusion in Appendix H
	esttab m1  using appendixH_table1.rtf, b(3) se(3) nogap r2 replace



* -----------------------------
* study 2, variable coding 
* -----------------------------

	** load data and set working directory for saving tables and figures
	cd "~/Dropbox/youthquake-replication/data"
	use "ees-votersurvey-2019-coded.dta", clear 

	cd "~/Dropbox/youthquake-replication/tables and figures"

	** distinguish between left and non left parties
	gen left=0 if family!=.
	replace left=1 if family==5 // socialist
	replace left=1 if family==6 // rad left
	replace left=1 if family==7 // green

	** coding gender
	gen woman=1 if D3==2
	replace woman=0 if D3==1

	** continuous age variable
	gen age=2019-D4_1

	** new age categories variable
	drop agegroup
	gen agegroup=1 if age<=29
	replace agegroup=2 if age>=30 & age<=39
	replace agegroup=3 if age>=40 & age<=49
	replace agegroup=4 if age>=50 & age<=59
	replace agegroup=5 if age>=60

	label define agegroupl 1 "-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+"
	label values agegroup agegroupl
	
	** religious groups
	gen religion=1 if D9==10			// atheist
	replace religion=1 if D9==11		// non believer/agnostic
	replace religion=2 if D9==1			// catholic
	replace religion=3 if D9>=2 & D9<=4	// other christian
	replace religion=4 if D9>=5 & D9>=9	// other

	label define religionl 1 "no religion" 2 "catholic" 3 "other christian" 4 "other religion"
	label values religion religionl


* -----------------------------	
* study 2, Figure 3 results
* -----------------------------

	** estimation for left parties
	eststo m1: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.woman i.countrycode if left==1 , cluster(respid country)

	** marginal effects, Figure 3a
	margins, at(galtan=(0.8(0.2)6.6) agegroup=(1 5))
	marginsplot, recast(line) recastci(rarea) title("") xtitle("GAL/TAN position of party") ytitle("Predicted PTV") addplot(hist galtan if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) saving(figure3a.gph, replace)

	** marginal effects, Figure 3b
	margins, at(lrecon=(0.1(0.1)4.2) agegroup=(1 5))
	marginsplot, recast(line) recastci(rarea) title("") xtitle("Economic LR position of party") ytitle("Predicted PTV") addplot(hist lrecon if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) saving(figure3b.gph, replace)

	

* -----------------------------	
* study 2, Figure 4 results
* -----------------------------

	** estimation for non-left parties
	eststo m2: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.woman i.countrycode if left==0 , cluster(respid country)

	** marginal effects, Figure 4a
	margins, at(galtan=(1.4(0.2)10) agegroup=(1 5))
	marginsplot, recast(line) recastci(rarea) title("") xtitle("GAL/TAN position of party") ytitle("Predicted PTV") addplot(hist galtan if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) saving(figure4a.gph, replace)

	** marginal effects, Figure 4b	
	margins, at(lrecon=(3.4(0.1)9.3) agegroup=(1 5))
	marginsplot, recast(line) recastci(rarea) title("") xtitle("Economic LR position of party") ytitle("Predicted PTV") addplot(hist lrecon if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) saving(figure4b.gph, replace)

	
	
* ---------------------------------------
* study 2, information for the appendix
* ---------------------------------------	

	** detailed estimates (figures 3 and 4) for appendix I
	esttab m1 m2 using appendixI_table1.rtf, b(3) se(3) r2 nogap replace

	** additional individual level controls, appendix J
	eststo m1: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.woman i.countrycode if left==1 , cluster(respid country)
eststo m2: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.woman i.countrycode if left==0 , cluster(respid country)

	eststo m1a: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.woman i.EDU i.countrycode if left==1 , cluster(respid country)
	eststo m2a: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.woman i.EDU i.countrycode if left==0 , cluster(respid country)

	eststo m1b: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.woman i.EDU i.religion i.countrycode if left==1 , cluster(respid country)
	eststo m2b: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.woman i.EDU i.religion i.countrycode if left==0 , cluster(respid country)

	esttab m1 m1a m1b m2 m2a m2b using appendixJ_table1.rtf, b(3) se(3) r2 nogap  replace
	
	** robustness: vote choice as outcome variable, appendix K
	eststo m1: vce2way reg votedforparty i.agegroup##c.galtan i.agegroup##c.lrecon i.woman i.countrycode if left==1 , cluster(respid country)

	margins, at(galtan=(0.8(0.2)6.6) agegroup=(1 5))
	marginsplot, recast(line) recastci(rarea) title("") xtitle("GAL/TAN position of party") ytitle("Predicted likelihood to vote for party") addplot(hist galtan if e(sample)==1, percent bin(20) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) saving(appendixK_figure1a.gph, replace)

	margins, at(lrecon=(0.1(0.1)4.2) agegroup=(1 5))
	marginsplot, recast(line) recastci(rarea) title("") xtitle("GAL/TAN position of party") ytitle("Predicted likelihood to vote for party") addplot(hist lrecon if e(sample)==1, percent bin(20) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) saving(appendixK_figure1b.gph, replace)

	eststo m2: reg votedforparty i.agegroup##c.galtan i.agegroup##c.lrecon i.woman i.countrycode if left==0 , cluster(country)

	margins, at(galtan=(1.4(0.2)10) agegroup=(1 5))
	marginsplot, recast(line) recastci(rarea) title("") xtitle("GAL/TAN position of party") ytitle("Predicted likelihood to vote for party") addplot(hist galtan if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) saving(appendixK_figure2a.gph, replace)

	margins, at(lrecon=(3.4(0.1)9.3) agegroup=(1 5))
	marginsplot, recast(line) recastci(rarea) title("") xtitle("Economic LR position of party") ytitle("Predicted likelihood to vote for party") addplot(hist lrecon if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) saving(appendixK_figure2b.gph, replace)


	** robustness: inclusion of party family FE (instead of country FE), appendix L
	vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.agegroup##i.family i.woman  if left==1 , cluster(respid country)
	sum galtan if e(sample)==1
	margins, at(galtan=(0.8(0.2)6.6) agegroup=(1 5))
	marginsplot, recast(line) recastci(rarea) title("") xtitle("GAL/TAN position of party") ytitle("Predicted PTV") addplot(hist galtan if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) saving(appendixL_figure1a.gph, replace)

	vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.agegroup##i.family i.woman i.woman  if left==0 , cluster(respid country)
	margins, at(galtan=(1.4(0.2)10) agegroup=(1 5))
	marginsplot, recast(line) recastci(rarea) title("") xtitle("GAL/TAN position of party") ytitle("Predicted PTV") addplot(hist galtan if e(sample)==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)100) axis(2)) ) saving(appendixL_figure1b.gph, replace)
	
	
	
* -----------------------------------
* study 3, figure 5 (present cases)
* -----------------------------------

	** load data
	cd "~/Dropbox/youthquake-replication/data"
	use "MPDataset_MPDS2024a_stata14" , clear 
	cd "~/Dropbox/youthquake-replication/tables and figures"

	** generate social LR position variable
	gen societyLR=(per601 + per603 + per605 + per608 + per704) - (per201 + per202 + per503 + per602 + per604 + per607)

	** keep only data of parties of interest for visualization
	keep if countryname=="United Kingdom" | countryname=="Denmark"
	keep if partyname=="Labour Party" & countryname=="United Kingdom" | partyname=="Social Democratic Party" & countryname=="Denmark"

	** generate election year variable
	gen year=date/100
	replace year=round(year,1)

	** plot positions of these parties since 1980
	keep if year>=1980
	twoway (connected societyLR year if partyname=="Labour Party") (connected societyLR year if partyname=="Social Democratic Party"),  xtitle("Election year") ytitle("Sociocultural position") saving(figure5a.gph, replace)
 
	** point of comparison, 'normal' shifts of social democratic parties
	cd "~/Dropbox/youthquake-replication/data"
	use "MPDataset_MPDS2024a_stata14" , clear 

	gen countrywest=1 if countryname=="Australia"
	replace countrywest=1 if countryname=="Austria"
	replace countrywest=1 if countryname=="Belgium"
	replace countrywest=1 if countryname=="Canada"
	replace countrywest=1 if countryname=="Denmark"
	replace countrywest=1 if countryname=="Finland"
	replace countrywest=1 if countryname=="France"
	replace countrywest=1 if countryname=="Germany"
	replace countrywest=1 if countryname=="Greece"
	replace countrywest=1 if countryname=="Iceland"
	replace countrywest=1 if countryname=="Ireland"
	replace countrywest=1 if countryname=="Italy"
	replace countrywest=1 if countryname=="Luxembourg"
	replace countrywest=1 if countryname=="Netherlands"
	replace countrywest=1 if countryname=="New Zealand"
	replace countrywest=1 if countryname=="Norway"
	replace countrywest=1 if countryname=="Portugal"
	replace countrywest=1 if countryname=="Spain"
	replace countrywest=1 if countryname=="Sweden"
	replace countrywest=1 if countryname=="Switzerland"
	replace countrywest=1 if countryname=="United Kingdom"
	replace countrywest=1 if countryname=="United States"

	keep if countrywest==1		// only keep western democracies

	gen societyLR=(per601 + per603 + per605 + per608 + per704) - (per201 + per202 + per503 + per602 + per604 + per607)
	keep if parfam==30
	gen year=date/100
	replace year=round(year,1)
	keep if year>=1980
	keep if pervote>=1

	bysort countryname partyname year: gen  no_election = _n

	bysort partyname no_election: gen lag_societyLR=societyLR[_n-1]
	bysort partyname no_election: gen lag2_societyLR=societyLR[_n-2]

	gen socchange=societyLR-lag_societyLR
	gen abs_socchange=abs(societyLR-lag_societyLR)

	gen socchange2=societyLR-lag2_societyLR
	gen abs_socchange2=abs(societyLR-lag2_societyLR)

	cd "~/Dropbox/youthquake-replication/tables and figures"
	hist abs_socchange2, bin(25) percent xtitle("Absolute change in position vs. e-2") saving(figure5b.gph, replace)	

	
* --------------------------	
* study 3, variable coding
* --------------------------		
	
	** load data and set working directory for saving tables and figures
	cd "~/Dropbox/youthquake-replication/data"
	use "BES2024_W26_Panel_v26.0.dta", clear

	cd "~/Dropbox/youthquake-replication/tables and figures"

	** code data and restrict to waves of interest -- post election 2015, 2019 

	/* election dates and corresponding post-election waves:
	7 May 2015 --> wave 6 (wave 6 was conducted by YouGov between 8th May 2015 and 26th May 2015)
	12 December 2019 --> wave 19 (Wave 19 was conducted between 13th Dec 2019 and 23rd December 2019)
	*/

	** code data and restrict to waves of interest
	keep if wave6==1  | wave19==1
	
	** keep only respondents who are true panel respondents (and participated in both 2015 and 2019 waves)
	keep if wave6==1 & wave19==1

	** vote choice
	clonevar Vote2015=generalElectionVoteW6
	clonevar Vote2019=generalElectionVoteW19

	gen LabVote2015=1 if Vote2015==2
	replace LabVote2015=0 if Vote2015==1				// Cons
	replace LabVote2015=0 if Vote2015>=3 & Vote2015<=9	// other parties

	gen LabVote2019=1 if Vote2019==2
	replace LabVote2019=0 if Vote2019==1				// Cons
	replace LabVote2019=0 if Vote2019>=3 & Vote2019<=13	// other parties

	** like/dislike ratings
	clonevar likeLab2015=likeLabW6
	recode likeLab2015 (9999=.)

	clonevar likeLab2019=likeLabW19
	recode likeLab2019 (9999=.)

	** socio-demographics
	clonevar age2015=ageW6
	clonevar age2019=ageW19

	clonevar gender2015=gender
	clonevar gender2019=gender

	clonevar edu2015=p_edlevelW6
	clonevar edu2019=p_edlevelW19

	gen ethnicminority2015=0 if p_ethnicityW6==1							// white
	replace ethnicminority2015=0 if p_ethnicityW6==2						// other white
	replace ethnicminority2015=1 if p_ethnicityW6>=3 & p_ethnicityW6<=15	// mixed or other groups

	gen ethnicminority2019=0 if p_ethnicityW19==1							// white
	replace ethnicminority2019=0 if p_ethnicityW19==2						// other white
	replace ethnicminority2019=1 if p_ethnicityW19>=3 & p_ethnicityW19<=15	// mixed or other groups

	gen religion2015=1 if p_religionW6==1							// not religious
	replace religion2015=2 if p_religionW6==2						// anglican
	replace religion2015=3 if p_religionW6==3						// catholic
	replace religion2015=4 if p_religionW6>=4 & p_religionW6<=9		// other christian
	replace religion2015=5 if p_religionW6>=10 & p_religionW6<=15	// other
	replace religion2015=4 if p_religionW6>=17 & p_religionW6<=19	// other christian

	gen religion2019=1 if p_religionW19==1							// not religious
	replace religion2019=2 if p_religionW19==2						// anglican
	replace religion2019=3 if p_religionW19==3						// catholic
	replace religion2019=4 if p_religionW19>=4 & p_religionW19<=9		// other christian
	replace religion2019=5 if p_religionW19>=10 & p_religionW19<=15	// other
	replace religion2019=4 if p_religionW19>=17 & p_religionW19<=19	// other christian

	** only keep relevant variables and reshape to long format
	keep Vote2015  Vote2019 LabVote2015  LabVote2019 likeLab2015  likeLab2019 age2015  age2019 gender2015  gender2019 edu2015  edu2019 ethnicminority2015 ethnicminority2019 religion2015 religion2019

	gen id = _n
	reshape long Vote LabVote likeLab age gender edu ethnicminority religion, i(id) j(year)

	** generate age in 2015 variable (groups)
	gen agegroup=1 if age>=18 & age<=29 & year==2015
	replace agegroup=2 if age>=30 & age<=39 & year==2015
	replace agegroup=3 if age>=40 & age<=49 & year==2015
	replace agegroup=4 if age>=50 & age<=59 & year==2015
	replace agegroup=5 if age>=60 & age<=100 & year==2015

	gen agegroupfull=agegroup
	bysort id : replace agegroupfull = agegroupfull[1] if agegroupfull==.
	drop agegroup
	rename agegroupfull agegroup

	** generate election variable
	gen election=1 if year==2015
	replace election=2 if year==2019

	label define electionl 1 "2015" 2 "2019"
	label values election electionl 

	** label religion variable
	label define religionl 1 "Not religious" 2 "Anglican" 3 "Catholic" 4 "Other Christian" 5 "Other"
	label values religion religionl


* -------------------------
* study 3, figure 6
* -------------------------
	
	** create variable that identifies respondents
	by id (year): gen wave_count = _N

	** regression estimation 
	eststo m1: reg LabVote i.agegroup##i.year i.gender if wave_count==2, cluster(id)

	** figure 6
	margins, at(agegroup=(1(1)5) year=(2015 2019) )
	mplotoffset, offset(0.2) recast(scatter) recastci(rspike) title("") xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+") ytitle("Predicted likelihood to vote Labour") saving(figure6.gph, replace)

	

* ------------------------------------------------
* study 3 - BESIP, information for the appendix
* ------------------------------------------------

	** appendix M, detailed estimates and additional individual-level controls
	eststo m2: reg LabVote i.agegroup##i.election i.gender i.edu , cluster(id)
	eststo m3: reg LabVote i.agegroup##i.election i.gender i.edu i.ethnicminority i.religion , cluster(id)

	esttab m1 m2 m3 using appendixM_table1.rtf, b(3) se(3) r2 nogap  replace

	** appendix P, replication with like/dislike as outcome variable
	reg likeLab i.agegroup##i.year if wave_count==2, cluster(id)

	margins, at(agegroup=(1(1)5) year=(2015 2019) )
	mplotoffset, offset(0.2) recast(scatter) recastci(rspike) title("") xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+") ytitle("Predicted like/dislike Labour") saving(appendixP_figure1.gph, replace)
	
	** appendix Q, replication with logistic regression approach
	eststo m1: logit LabVote i.agegroup##i.year  i.gender , cluster(id)

	margins, at(agegroup=(1(1)5) year=(2015 2019) )
	mplotoffset, offset(0.2) recast(scatter) recastci(rspike) title("") xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+") ytitle("Predicted likelihood to vote Labour") saving(appendixQ_figure1.gph, replace)

	esttab m1 using appendixQ_table1.rtf, b(3) se(3) nogap replace

	** appendix N, replication including the post 2017 election wave
	
		* load data
	cd "~/Dropbox/youthquake-replication/data"
	use "BES2024_W26_Panel_v26.0.dta", clear
	cd "~/Dropbox/youthquake-replication/tables and figures"
	
		* code data and restrict to waves of interest -- post election 2015, 2017, 2019 

		/* election dates and corresponding post-election waves:
		7 May 2015 --> wave 6 (Wave 6 was conducted by YouGov between 8th May 2015 and 26th May 2015.)
		8 June 2017 --> wave 13 (Wave 13 was conducted by YouGov between 9th June 2017 and 23rd June 2017.)
		12 December 2019 --> wave 19 (Wave 19 was conducted by YouGov between 13th December 2019 and 
		23rd December 2019. )
		*/

	keep if wave6==1 | wave13==1 | wave19==1
	keep if wave6==1 & wave13==1 & wave19==1		// keep only real panel respondents
	
	clonevar Vote2015=generalElectionVoteW6
	clonevar Vote2017=generalElectionVoteW13
	clonevar Vote2019=generalElectionVoteW19

	gen LabVote2015=1 if Vote2015==2
	replace LabVote2015=0 if Vote2015==1				// Cons
	replace LabVote2015=0 if Vote2015>=3 & Vote2015<=9	// other parties

	gen LabVote2017=1 if Vote2017==2
	replace LabVote2017=0 if Vote2017==1				// Cons
	replace LabVote2017=0 if Vote2017>=3 & Vote2017<=9	// other parties

	gen LabVote2019=1 if Vote2019==2
	replace LabVote2019=0 if Vote2019==1				// Cons
	replace LabVote2019=0 if Vote2019>=3 & Vote2019<=13	// other parties

	clonevar likeLab2015=likeLabW6
	recode likeLab2015 (9999=.)

	clonevar likeLab2017=likeLabW13
	recode likeLab2017 (9999=.)

	clonevar likeLab2019=likeLabW19
	recode likeLab2019 (9999=.)

	clonevar age2015=ageW6
	clonevar age2017=ageW13
	clonevar age2019=ageW19

	clonevar gender2015=gender
	clonevar gender2017=gender
	clonevar gender2019=gender
	
	clonevar edu2015=p_edlevelW6
	clonevar edu2017=p_edlevelW13
	clonevar edu2019=p_edlevelW19

		* only keep relevant variables and reshape to long format
	keep Vote2015 Vote2017 Vote2019 LabVote2015 LabVote2017 LabVote2019 likeLab2015 likeLab2017 likeLab2019 age2015 age2017 age2019 gender2015 gender2017 gender2019 edu2015 edu2017 edu2019

	gen id = _n
	reshape long Vote LabVote likeLab age gender edu, i(id) j(year)

		* generate age in 2015 variable (groups)
	gen agegroup=1 if age>=18 & age<=29 & year==2015
	replace agegroup=2 if age>=30 & age<=39 & year==2015
	replace agegroup=3 if age>=40 & age<=49 & year==2015
	replace agegroup=4 if age>=50 & age<=59 & year==2015
	replace agegroup=5 if age>=60 & age<=100 & year==2015

	gen agegroupfull=agegroup
	bysort id : replace agegroupfull = agegroupfull[1] if agegroupfull==.
	drop agegroup
	rename agegroupfull agegroup

		* generate election variable
	gen election=1 if year==2015
	replace election=2 if year==2017
	replace election=3 if year==2019
	
	label define electionl 1 "2015" 2 "2017" 3 "2019"
	label values election electionl 


		* estimates reported in appendix N
	eststo m1: reg LabVote i.agegroup##i.election  i.gender , cluster(id)

	margins, at(agegroup=(1(1)5) election=(1 2 3) )
	mplotoffset, offset(0.2) recast(scatter) recastci(rspike) title("") xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+") ytitle("Predicted likelihood to vote Labour") xtitle("Age group in 2015") legend(cols(3)) saving(appendixN_figure1.gph, replace)

	eststo m2: reg LabVote i.agegroup##i.election i.gender i.edu , cluster(id)

	esttab m1 m2 using appendixN_table1.rtf, b(3) se(3) r2 nogap  replace

	reg likeLab i.agegroup##i.election i.gender , cluster(id)
	margins, at(agegroup=(1(1)5) election=(1 2 3) )
	mplotoffset, offset(0.2) recast(scatter) recastci(rspike) title("") xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+") ytitle("Predicted like/dislike Labour") xtitle("Age group in 2015") legend(cols(3)) saving(appendixN_figure2.gph, replace)
	
	
	
* -------------------------
* study 3, figure 7
* -------------------------	
	
	** load data for 2007
	cd "~/Dropbox/youthquake-replication/data"
	use "denmark_2007", clear
	
	cd "~/Dropbox/youthquake-replication/tables and figures"

	** variable coding for 2007
	gen woman=0 if v12!=.
	replace woman=1 if v12==2

	gen likedislike_SD=v87
	recode likedislike_SD (88=.) (98=.)

	gen voteSD=0 if v28>=2 & v28<=11
	replace voteSD=1 if v28==1

	gen age=v13
	gen agegroup=1 if age>=18 & age<=29
	replace agegroup=2 if age>=30 & age<=39
	replace agegroup=3 if age>=40 & age<=49
	replace agegroup=4 if age>=50 & age<=59
	replace agegroup=5 if age>=60 & age<=100
	
	** estimation and generate figure 7
	reg voteSD i.agegroup woman
	margins, at(agegroup=(1(1)5))
	marginsplot, title("") recast(scatter) recastci(rspike)  xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+" ) xtitle("") ytitle("Predicted likelihood to vote SD") saving(figure7a.gph, replace)

	** load data for 2015
	cd "~/Dropbox/youthquake-replication/data"
	use "denmark_2015", clear
	
	cd "~/Dropbox/youthquake-replication/tables and figures"
	
	** variable coding for 2015
	gen woman=0 if V5!=.
	replace woman=1 if V5==2

	gen age=2015-V6
	replace age=. if V6==99

	gen agegroup=1 if age>=18 & age<=29
	replace agegroup=2 if age>=30 & age<=39
	replace agegroup=3 if age>=40 & age<=49
	replace agegroup=4 if age>=50 & age<=59
	replace agegroup=5 if age>=60 & age<=100

	gen voteSD=0 if V51>=2 & V51<=11
	replace voteSD=1 if V51==1

	gen likedislike_SD=V67
	recode likedislike_SD (88=.)

	gen edu=V351
	recode edu (88=.)
	
	** estimation and generate figure 7
	reg voteSD i.agegroup woman
	margins, at(agegroup=(1(1)5))
	marginsplot, title("") recast(scatter) recastci(rspike)  xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+" ) xtitle("") ytitle("Predicted likelihood to vote SD") saving(figure7b.gph, replace)

	
	
* ------------------------------------------------
* study 3 - Denmark, information for the appendix
* ------------------------------------------------

	** appendix O, 2007 data, estimates and control for education

	cd "~/Dropbox/youthquake-replication/data"
	use "denmark_2007", clear
	
	cd "~/Dropbox/youthquake-replication/tables and figures"

	gen woman=0 if v12!=.
	replace woman=1 if v12==2

	gen likedislike_SD=v87
	recode likedislike_SD (88=.) (98=.)

	gen voteSD=0 if v28>=2 & v28<=11
	replace voteSD=1 if v28==1

	gen age=v13
	gen agegroup=1 if age>=18 & age<=29
	replace agegroup=2 if age>=30 & age<=39
	replace agegroup=3 if age>=40 & age<=49
	replace agegroup=4 if age>=50 & age<=59
	replace agegroup=5 if age>=60 & age<=100

	eststo m1: reg voteSD i.agegroup woman
	eststo m2: reg voteSD i.agegroup woman i.v508
	esttab m1 m2 using appendixO_table1.rtf, b(3) se(3) nogap r2 replace
	
	** appendix P, 2007 data, like/dislike replication
	reg likedislike_SD i.agegroup woman
	margins, at(agegroup=(1(1)5))
	marginsplot, title("") recast(scatter) recastci(rspike)  xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+" ) xtitle("") ytitle("Predicted like/dislike SD") saving(appendixP_figure2a.gph, replace)

	
	** appendix O, 2015 data , estimates and control for education
	cd "~/Dropbox/youthquake-replication/data"
	use "denmark_2015", clear
	
	cd "~/Dropbox/youthquake-replication/tables and figures"
	
	gen woman=0 if V5!=.
	replace woman=1 if V5==2

	gen age=2015-V6
	replace age=. if V6==99

	gen agegroup=1 if age>=18 & age<=29
	replace agegroup=2 if age>=30 & age<=39
	replace agegroup=3 if age>=40 & age<=49
	replace agegroup=4 if age>=50 & age<=59
	replace agegroup=5 if age>=60 & age<=100

	gen voteSD=0 if V51>=2 & V51<=11
	replace voteSD=1 if V51==1

	gen likedislike_SD=V67
	recode likedislike_SD (88=.)

	gen edu=V351
	recode edu (88=.)
	
	eststo m1: reg voteSD i.agegroup woman
	eststo m2: reg voteSD i.agegroup woman i.edu
	esttab m1 m2 using appendixO_table2.rtf, b(3) se(3) nogap r2 replace
	
	** appendix P, 2015 data, like/dislike replication
	reg likedislike_SD i.agegroup woman
	margins, at(agegroup=(1(1)5))
	marginsplot, title("") recast(scatter) recastci(rspike)  xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+" ) xtitle("") ytitle("Predicted like/dislike SD") saving(appendixP_figure2b.gph, replace)


	** appendix Q, replication with logistic regression estimation
	
		* 2007
	cd "~/Dropbox/youthquake-replication/data"
	use "denmark_2007", clear
	cd "~/Dropbox/youthquake-replication/tables and figures"

	gen woman=0 if v12!=.
	replace woman=1 if v12==2

	gen voteSD=0 if v28>=2 & v28<=11
	replace voteSD=1 if v28==1

	gen age=v13

	gen agegroup=1 if age>=18 & age<=29
	replace agegroup=2 if age>=30 & age<=39
	replace agegroup=3 if age>=40 & age<=49
	replace agegroup=4 if age>=50 & age<=59
	replace agegroup=5 if age>=60 & age<=100

	eststo m1: logit voteSD i.agegroup woman
	margins, at(agegroup=(1(1)5))
	marginsplot, title("") recast(scatter) recastci(rspike)  xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+" ) xtitle("") ytitle("Predicted likelihood to vote SD") saving(appendixQ_figure2a.gph, replace)

		* 2015
	cd "~/Dropbox/youthquake-replication/data"
	use "denmark_2015", clear
	cd "~/Dropbox/youthquake-replication/tables and figures"

	gen woman=0 if V5!=.
	replace woman=1 if V5==2

	gen age=2015-V6
	replace age=. if V6==99

	gen agegroup=1 if age>=18 & age<=29
	replace agegroup=2 if age>=30 & age<=39
	replace agegroup=3 if age>=40 & age<=49
	replace agegroup=4 if age>=50 & age<=59
	replace agegroup=5 if age>=60 & age<=100

	gen voteSD=0 if V51>=2 & V51<=11
	replace voteSD=1 if V51==1

	eststo m2: logit voteSD i.agegroup woman
	margins, at(agegroup=(1(1)5))
	marginsplot, title("") recast(scatter) recastci(rspike)  xlabel(1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+" ) xtitle("") ytitle("Predicted likelihood to vote SD") saving(appendixQ_figure2b.gph, replace)


	esttab m1 m2 using appendixQ_table2.rtf, b(3) se(3) nogap replace
	

* -----------------------------------------	
* APC analysis, reported in appendix R
* -----------------------------------------	

	** load data
	cd "~/Dropbox/youthquake-replication/data"
	use "gmp.dta" , clear

	** decade dummies 
	gen decade=1940 if year>=1940 & year<=1949
	replace decade=1950 if year>=1950 & year<=1959
	replace decade=1960 if year>=1960 & year<=1969
	replace decade=1970 if year>=1970 & year<=1979
	replace decade=1980 if year>=1980 & year<=1989
	replace decade=1990 if year>=1990 & year<=1999
	replace decade=2000 if year>=2000 & year<=2010
	replace decade=2010 if year>=2010 & year<=2020

	** new age variable
	gen agegroup=1 if age<=29
	replace agegroup=2 if age>=30 & age<=39
	replace agegroup=3 if age>=40 & age<=49
	replace agegroup=4 if age>=50 & age<=59
	replace agegroup=5 if age>=60

	label define agegroupl 1 "18-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+"
	label values agegroup agegroupl

	** approximate year of birth
	gen yearbirth=year-age

	** generations
	gen generation=1 if yearbirth<1928 & yearbirth!=.			// greatest -1928
	replace generation=2 if yearbirth>=1928 & yearbirth<=1945 	// silent generation 1928-45
	replace generation=3 if yearbirth>=1946 & yearbirth<=1964 	// boomers 1946-64
	replace generation=4 if yearbirth>=1965 & yearbirth<=1980 	// gen X 1965-80
	replace generation=5 if yearbirth>=1981 & yearbirth<=1996 	// millenials 1981-96
	replace generation=6 if yearbirth>=1997 & yearbirth!=. 		// gen Z 1997- 

	label define generationl 1 "Greatest" 2 "Silent" 3 "Boomers" 4 "Gen. X" 5 "Millenials" 6 "Gen. Z"
	label values generation generationl

	** new left variable that does not consider social liberal parties as left
	gen voteleft_new=voteleft
	replace voteleft_new=0 if votelib==1

	** only keep countries in West (and Greece which we also consider Western)
	keep if west==1 | isoname=="Greece"
	keep if decade!=.

	** merge with data on positions and polarization (by year) based on CMP
	gen isoyear=iso+string(year)

	merge m:1 isoyear using "cmp_positions.dta" 
	drop if _merge==2
	drop _merge

	** merge with gallagher's election indices data
	merge m:1 isoyear using "gallagher-indices-formerge.dta" 
	drop if _merge==2
	drop _merge

	** numerical country code for analyses
	encode iso, gen(isonum)

	** analyses
	cd "~/Dropbox/youthquake-replication/tables and figures"

	eststo m1: mixed voteleft_new i.agegroup##c.maxleft i.agegroup##c.minnonleft   i.sex  effnv lsq || isoyear:agegroup  if year>=1980, var
	eststo m2: mixed voteleft_new i.agegroup##c.maxleft i.agegroup##c.minnonleft i.generation##c.maxleft i.generation##c.minnonleft c.year##c.maxleft c.year##c.minnonleft  i.sex  effnv lsq || isoyear:agegroup generation if year>=1980, var

	esttab m1 m2  using appendixR_table1.rtf, b(3) se(3) nogap r2 replace	
	
	
* ----------------------------------------	
* test for role of valence, appendix S	
* ----------------------------------------	

	** load data (ESS)
	cd "~/Dropbox/youthquake-replication/data"
	use "ees-votersurvey-2019-coded.dta", clear 

	cd "~/Dropbox/youthquake-replication/tables and figures"

	** distinguish between left and non left parties
	gen left=0 if family!=.
	replace left=1 if family==5 // socialist
	replace left=1 if family==6 // rad left
	replace left=1 if family==7 // green

	** code additional variables (sociodemo)
	gen woman=1 if D3==2
	replace woman=0 if D3==1

	gen age=2019-D4_1

	drop agegroup
	gen agegroup=1 if age<=29
	replace agegroup=2 if age>=30 & age<=39
	replace agegroup=3 if age>=40 & age<=49
	replace agegroup=4 if age>=50 & age<=59
	replace agegroup=5 if age>=60

	label define agegroupl 1 "-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60+"
	label values agegroup agegroupl

	** code trust in parliament
	gen trustparliament=0 if Q18_1==5		// no, not at all
	replace trustparliament=1 if Q18_1==4	// no, not really
	replace trustparliament=2 if Q18_1==3	// neither trust nor distrust
	replace trustparliament=3 if Q18_1==2	// yes, somewhat
	replace trustparliament=4 if Q18_1==1	// yes, totally

	** code economic evaluations
	gen socioeco=0 if Q19==5 		// A lot worse
	replace socioeco=1 if Q19==4	// A little worse
	replace socioeco=2 if Q19==3	// Stayed the same
	replace socioeco=3 if Q19==2	// A little better
	replace socioeco=4 if Q19==1	// A lot better

	**  estimations with valence controls 
	eststo m1: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon  i.woman i.countrycode if left==1 & 	trustparliament!=. & socioeco!=., cluster(respid country)
	eststo m3: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon  i.woman i.countrycode if left==0 & trustparliament!=. & socioeco!=., cluster(respid country)

	eststo m2: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.agegroup##c.trustparliament i.agegroup##c.socioeco i.woman i.countrycode if left==1 , cluster(respid country)
	eststo m4: vce2way reg ptv i.agegroup##c.galtan i.agegroup##c.lrecon i.agegroup##c.trustparliament i.agegroup##c.socioeco i.woman i.countrycode if left==0 , cluster(respid country)

	esttab m1 m2 m3 m4 using appendixS_table1.rtf, b(3) se(3) nogap replace


	
	
	
	



